<template>
  <el-dialog
    title="修改"
    append-to-body
    :visible.sync="dialogVisible"
    width="500px"
  >
    <el-form :model="form" ref="form" :rules="rules" label-width="130px" size="mini">
      <el-form-item label="去年实际：" prop="money1">
        <el-input v-model="form.money1" placeholder="请输入" clearable></el-input>
      </el-form-item>
      <el-form-item label="当年预算：" prop="money2">
        <el-input v-model="form.money2" placeholder="请输入" clearable></el-input>
      </el-form-item>
      <el-form-item label="当年预计完成：" prop="money3">
        <el-input v-model="form.money3" placeholder="请输入" clearable></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="order">
        <el-input type="textarea" v-model="form.order" placeholder="请输入" clearable></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <div class="dialog-footer">
        <el-button size="mini" type="primary" @click="handle_submit">确定</el-button>
        <el-button size="mini" @click="dialogVisible = false">取消</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { getCookie } from "@/common/js/cookie";
import { $budgetAPI } from "@/api";
export default {
  data(){
    return {
      dialogVisible: false,
      form: {
        money1: "",
        money2: "",
        money3: "",
        order: "",
        id: null
      },
      rules: {
        money1: [{required: true, message: '必填', trigger: "blur"}],
        money2: [{required: true, message: '必填', trigger: "blur"}],
        money3: [{required: true, message: '必填', trigger: "blur"}],
        order: [{required: true, message: '必填', trigger: "blur"}],
      }
    }
  },
  methods: {
    init(row){
      for(let key in this.form){
        this.form[key] = row[key];
      }
      this.dialogVisible = true;
    },
    async handle_submit() {
      await this.$refs["form"].validate();
      $budgetAPI.updateBudgetingData(
        { ...this.form, token: getCookie("token") },
        res => {
          if(res.code == 0){
            this.$message.success("修改成功");
            this.$emit('refresh');
            this.dialogVisible = false;
            this.$refs.form.resetFields();
          }
        },
        err => {
          
        }
      )
    }
  }
}
</script>